package com.aaa.controller.mht;

import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.entity.mht.MhtRecord;
import com.aaa.service.mht.MhtRecordService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("mhtRecord")
public class MhtRecordController {

    @Autowired
    private MhtRecordService mhtRecordService;
    /**
     * 检测该电话号码是否已经做过该试题
     */
    @GetMapping("checkRecord")
    @ResponseBody
    public LayData checkUserRecord(MhtRecord mhtRecord){
        MhtRecord mhtRecord1 = mhtRecordService.checkUserRecord(mhtRecord);
        return new LayData(mhtRecord1);
    }
    /**
     * 添加该用户记录
     */
    @PostMapping("addRecord")
    @ResponseBody
    public LayData addUserRecord(MhtRecord mhtRecord){
        int id = mhtRecordService.insertUserRecord(mhtRecord);
        return new LayData(id);
    }
    /**
     * 查询所有的做题记录
     */
    @RequestMapping("showRecord")
    @ResponseBody
    public LayData showAllRecord(MyPage myPage,MhtRecord mhtRecord){
        PageInfo allRecord = mhtRecordService.findAllRecord(myPage,mhtRecord);
        return new LayData(allRecord);
    }
    /**
     * 查询测试的详情信息（做题答案）
     */
    @RequestMapping("showRecordAnswer{id}")
    @ResponseBody
    public LayData showAnswer(@PathVariable Integer id,MyPage myPage){
        PageInfo allRecord = mhtRecordService.findRecordAnswer(myPage,id);
        return new LayData(allRecord);
    }
}
